package org.jg.arkanoid.gameobjects;

import java.awt.Color;

import org.jg.arkanoid.engine.collider.CollisionEvent;
import org.jg.arkanoid.gameobjects.factories.ObjectPanelFactory;
import org.jg.arkanoid.util.Vector;
import javax.swing.JPanel;

public class GameObject {
	protected int height;
	protected int width;
	protected Color color;
	protected Vector position;
	protected JPanel panel;
	protected boolean shouldBeDestoryed;
	
	public void callCollision(CollisionEvent event) {}
	
	public boolean isCollidable()
	{
		return true;
	}
	
	public GameObject(){
		shouldBeDestoryed = false;
	}
	
	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public Vector getPosition() {
		return position;
	}

	public void setPosition(Vector position) {
		this.position = position;
	}
	
	public Vector getCentroid(){
		return position.addVector(width/2, height/2);
	}
	
	public JPanel getPanel() {
		return panel;
	}
	
	public void setPanel(JPanel panel) {
		this.panel = panel;
	}
	
	public JPanel getPanel(boolean redraw) {
		if(redraw)
			redrawObject();
		
		return panel;
	}
	
	public void redrawObject(){
		if(panel == null)
			createPanel();
		
		panel.repaint();
	}
	
	private void createPanel(){
		ObjectPanelFactory.getFactoryInstance().setPanel(this);
	}
	
	public boolean isShouldBeDestoryed() {
		return shouldBeDestoryed;
	}
	public void setShouldBeDestoryed(boolean shouldBeDestoryed) {
		this.shouldBeDestoryed = shouldBeDestoryed;
	}
}
